<!DOCTYPE html>
<html lang="en">


{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">文章分类</div>
                        </div>
                        <div class="widget-body  am-fr">


                            <!--筛选搜索-->
                            <form action="">
                                <table class="table">
                                        <a href="{:url('category_add')}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>新增分类</a>
                                </table>
                            </form>

                            <!--<form id="searchform" action="{:Url('search')}"  method="post" >-->
                                <!--<table class="table">-->
                                    <!--<tbody>-->
                                    <!--<td  class="col-sm-3">-->
                                        <!--<input type="text" class="form-control" value="{$Think.get.consignee}" placeholder="搜索" name="consignee">-->
                                    <!--</td>-->
                                    <!--<td  class="col-sm-2">-->
                                        <!--<select class="form-control input-sm" name="shipping_status">-->
                                            <!--<option value="0">选择文章类别</option>-->



                                        <!--</select>-->
                                    <!--</td>-->
                                    <!--<td>-->
                                    <!--<div class="col-sm-12">-->
                                        <!--<button class="btn btn-primary" type="submit" >搜索</button>-->
                                        <!--<a href="{:url('article_list')}"><button type="button" id="loading-example-btn" class="btn btn-white btn-sm"><i class="fa fa-refresh"></i> 刷新</button></a>-->
                                    <!--</div>-->
                                    <!--</td>-->
                                    <!--<td>-->
                                        <!--<div class="form-group pull-right">-->
                                            <!--<a href="{:url('article_add')}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>新增分类</a>-->
                                        <!--</div>-->
                                    <!--</td>-->
                                    <!--</tbody>-->
                                <!--</table>-->
                            <!--</form>-->
                            <div class="am-u-sm-12">
                                <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                    <thead>
                                    <tr>

                                        <th>分类名称</th>
                                        <th>所属分组</th>
                                        <th>描述</th>
                                        <th>状态</th>
                                        <th>排序</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {foreach name="list" key="key" item="v"}
                                    <tr class="gradeX">
                                        <td>{$v.cat_name}</td>
                                        <td>{$v.cat_type}</td>
                                        <td>{$v.cat_desc}</td>
                                        <td>
                                            {if $v.show_in_nav eq 1}
                                            <button type="button" class="btn btn-primary btn-sm" onclick="changedisable(this)" data-val="0" masterid='{$v.cat_id}'><i class="fa fa-check" ></i>&nbsp;显示</button>
                                            {else}
                                            <button class="btn btn-default btn-sm " type="button" onclick="changedisable(this)" data-val="1" masterid='{$v.cat_id}' ><i class="fa fa-times" ></i>
                                                <span class="bold" >禁用</span>
                                            </button>
                                            {/if}
                                        </td>
                                        <td>
                                            {$v.sort_order}
                                        </td>
                                        <td>
                                            <div class="tpl-table-black-operation">
                                                <a href="{:Url('category_edit')}?cat_id={$v.cat_id}">
                                                    <i class="am-icon-pencil"></i> 编辑
                                                </a>
                                                <a onclick="del_button({$v.cat_id});" href="javascript:void(0);" href="javascript:;" class="tpl-table-black-operation-del">
                                                    <i class="fa fa-trash-o"></i> 删除
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                    {/foreach}
                                    <!-- more data -->
                                    </tbody>
                                </table>
                            </div>
                            <div class="am-u-lg-10 am-cf">

                                <div class="am-fr">
                                    <ul class="am-pagination tpl-pagination">
                                        {$list->render()}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
{include file='Public:script'}
<link href="/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css">
<script src="/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script>
    // 删除按钮
    function del_button(id, className) {
        layer.confirm("确定删除？", {btn: ["确定","取消"], shade: 0.5}, function(){
            // 删除权限组
            $.post("{:url('del')}", {id: id}, function(res) {
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                    return false;
                }

                layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 1}, function() {
                    layer.closeAll('page');
                    location.reload();
                });
            });
        }, function () {});
    }

    // 启用禁用修改
    function changedisable(e,d){
        cat_id      = $(e).attr('masterid');
        show_in_nav = $(e).attr('data-val');

        // 状态修改
        $.post("{:url('change')}", {cat_id: cat_id, show_in_nav: show_in_nav}, function(ret){
            if(ret.code != 200){
                layer.tips(ret.msg, e, {tips: [4, 'red']});
            }

            layer.msg(ret.msg, {time: 2000, shift: 4}, function(){
                if(show_in_nav == 0) {
                    $(e).toggleClass('btn-default');
                    $(e).toggleClass('btn-primary');
                    $(e).html("<i class='fa fa-times'></i> <span class='bold'>禁用</span>");
                    $(e).attr('data-val','1');
                    return false;
                }

                $(e).toggleClass('btn-default');
                $(e).toggleClass('btn-primary');
                $(e).html("<i class='fa fa-check'></i>&nbsp;显示");
                $(e).attr('data-val','0');
                return false;
            });
        });
    }
</script>
</html>